package com.zfsmart.component.common.util;

import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class OssUtil {
    private static ClientConfiguration configuration;

    @PostConstruct
    public void init() {
        configuration = new ClientConfiguration();
        //设置HTTP最大连接数(默认为50)
        configuration.setMaxConnections(100);
        //设置TCP连接超时时间(默认为50000毫秒)
        configuration.setConnectionTimeout(10000);
    }

    public OSSClient getOssClient(String endpoint, String accessKeyId, String accessKeySecret) {
        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret, configuration);
        return ossClient;
    }

    public OSSClient getDownloadClient(String downloadEndpoint, String accessKeyId, String accessKeySecret) {
        OSSClient ossClient = new OSSClient(downloadEndpoint, accessKeyId, accessKeySecret, configuration);
        return ossClient;
    }
}